import { getMineForm } from "../api/index"
import { getNoneFinish, getFinishWork } from "../api/manage"



Page({

  data: {
    mineform: [],
    allMineForm: [],
    items2: [
      {
        title: '标题文字',
        icon: 'https://gw.alipayobjects.com/mdn/rms_3a7189/afts/img/A*L8FjQ7lSdq4AAAAAAAAAAAAAARQnAQ',
      },
      {
        title: '标题文字',
        icon: 'https://gw.alipayobjects.com/mdn/rms_3a7189/afts/img/A*L8FjQ7lSdq4AAAAAAAAAAAAAARQnAQ',
      },
    ],
    list: ['全部', '月度', '季度', '半年度', '年度', '自定义'],
    defaultValue: '全部',
    // 待办任务数量
    notHanderWorkCount: 0,
    // 已办任务数量
    handerWorkCount: 0
  },
  onLoad() {
    // dd.setNavigationBar({ title: "登录" })
    // let dd = ""
    dd.getStorage({
      key: 'currentCity',
      success: (res) => {
        // this.data.userDDId = res.data.value
        let data = {
          userDDId: res.data.value.userId
        }
        getMineForm(data).then(rs => {
          this.setData({
            allMineForm: rs.data,
          })
          this.filterMyPmFunc("全部")
        })
        getNoneFinish(data).then(res => {
          console.log('待办任务列表', res);
          this.setData({
            notHanderWorkCount: res.data.length
          })
        })
        getFinishWork(data).then(res => {
          console.log('已办任务列表', res);
          this.setData({
            handerWorkCount: res.data.length
          })
        })
      },
      fail: function (res) {
        dd.alert({ content: res.errorMessage });
      }
    });

  },

  // 我的绩效类型选择change
  myPmTypePikerOk(e) {
    this.filterMyPmFunc(e)
  },

  // 过滤我的绩效函数
  filterMyPmFunc(type) {
    console.log(this.data);
    console.log('当前类型:', type);
    if (type == '全部') {
      this.setData({
        mineform: this.data.allMineForm
      })
    } else {
      let allMineD = this.data.allMineForm

      let rMineD = allMineD.filter((mine) => {
        return mine.pmPeriodName == type
      })
      this.setData({
        mineform: rMineD
      })
    }
  },



  // 待办事项
  backlog() {
    dd.navigateTo({
      url: '/pages/usual/backlog?type=0'
    })
  },


  // 已办任务
  inform() {
    dd.navigateTo({
      url: '/pages/usual/backlog?type=1'
    })
  },

  lhpTap(e) {
    let eItem = e.target.dataset.index
    console.log(eItem);
    dd.navigateTo({
      url: `/pages/usual/performancedetail/performancedetail?pmid=${eItem.pmId}&userName=${eItem.pmUserName
        }&avatar=${eItem.avatar}&dept=${eItem.pmDeptName}`,
    })
  }

});
